﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Omu.Awesome.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class RolesLookupController : LookupController
    {
        private readonly IRepo<Role> r;

        public RolesLookupController(IRepo<Role> r)
        {
            this.r = r;
        }
        public override ActionResult SearchForm()
        {
            return Content("");
        }

        [HttpPost]
        public ActionResult Search(IEnumerable<int> selected)
        {
            return View(@"Awesome\LookupList", r.GetAll().Where(o => (selected == null || !selected.Contains(o.Id))));
        }

        public ActionResult Selected(IEnumerable<int> selected)
        {
            return View(@"Awesome\LookupList", r.GetAll().Where(o => selected != null && selected.Contains(o.Id)));
        }

        public ActionResult GetMultiple(IEnumerable<int> selected)
        {
            return Json(r.GetAll().Where(o => selected.Contains(o.Id)).Select(v => new { Text = v.Name }));
        } 
    }
}